package com.cw1.protoType.deepclone;

/**
 * @Author qiuMi
 * @description 测试 - 深/浅拷贝
 * @Date 2022-10-17 22:00
 **/
public class TestClone {
    public static void main(String[] args) throws CloneNotSupportedException {
        DeepProtoType1 deepProtoType1 = new DeepProtoType1();
        deepProtoType1.name = "123";
        deepProtoType1.deepCloneableTarget = new DeepCloneableTarget("你好","我的");

        // 方式一完成拷贝
        DeepProtoType1 clone = (DeepProtoType1) deepProtoType1.clone();
        System.out.println(deepProtoType1.name + "hashCode:" + deepProtoType1.deepCloneableTarget.hashCode());
        System.out.println(clone.name + "hashCode:" + clone.deepCloneableTarget.hashCode());

        System.out.println(" ============== ");

        // 方式二完成 深拷贝
        DeepProtoType1 deepProtoType2 = new DeepProtoType1();
        deepProtoType2.name = "1234";
        deepProtoType2.deepCloneableTarget = new DeepCloneableTarget("你好2","我的2");
        DeepProtoType1 deepClone = (DeepProtoType1) deepProtoType2.deepClone();
        System.out.println(deepProtoType2.name + "hashCode:" + deepProtoType2.deepCloneableTarget.hashCode());
        System.out.println("deepClone" + deepClone.name + "hashCode:" + deepClone.deepCloneableTarget.hashCode());

    }
}
